/*
 * Util.java
 *
 * Copyright (c) 2008 Teamnet. All Rights Reserved.
 *
 * This source file may not be copied, modified or redistributed,
 * in whole or in part, in any form or for any reason, without the express
 * written consent of Teamnet.
 */

package ro.prj.manager;

/**
 * This class is used to todo
 */
public class Util {
    public static void initLog4J(){
        
        System.setProperty("log4j.rootLogger","info, R");
        System.setProperty("log4j.logger.ro.teamnet","debug,stdout,R");
        System.setProperty("log4j.logger.org","info,debug,stdout,R");
        System.setProperty("log4j.logger.com","info,debug,stdout,R");
        System.setProperty("log4j.appender.R","org.apache.log4j.RollingFileAppender");
        System.setProperty("log4j.appender.R.File","d:/log_desktop/log.txt");
        System.setProperty("log4j.appender.R.MaxFileSize","2000KB");
        System.setProperty("log4j.appender.R.MaxBackupIndex","5");
        System.setProperty("log4j.appender.R.layout","org.apache.log4j.PatternLayout");
        System.setProperty("log4j.appender.R.layout.ConversionPattern","%d{dd-MM-yyyy HH:mm:ss} %p %c - %m%n");
    }

    public static byte[] append(byte[] src,byte[] appender,String replacer){
        byte[] ret;

        StringBuilder sb1=new StringBuilder();
        StringBuilder sb2=new StringBuilder();

        for(byte b:src){
            sb1.append((char)b);
        }
        for(byte b:appender){
            sb2.append((char)b);
        }

        String rez=sb1.indexOf(sb2.toString())>0?sb1.toString():sb1.toString().replace(replacer.trim(),sb2.toString());
        char[] cc=rez.toCharArray();
        ret=new byte[cc.length];
        for(int i=0;i<ret.length;i++)
            ret[i]=Byte.decode(String.valueOf((int)cc[i]));


        return ret;
    }


    public static void main(String[] args) {
        String s1="Mama are mere\n si tata are pere \n<!-- de inlocuit -->";
        String s2="si copilu are pere\n<!-- de inlocuit -->";
        String s3="<!-- de inlocuit -->";

        byte[] b1= new byte[s1.length()];
        byte[] b2= new byte[s2.length()];

        int l=0;
        for(char c:s1.toCharArray()){
           b1[l++]=Byte.decode(String.valueOf((int)c));
        }
        l=0;
        for(char c:s2.toCharArray()){
           b2[l++]=Byte.decode(String.valueOf((int)c));
        }
       

        append(b1, b2, s3);

    }
}
